home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / ToolManager / Source / Library / locale.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  80 lines

  1. /*
  2.  * locale.c  V3.1
  3.  *
  4.  * ToolManager library localization support
  5.  *
  6.  * Copyright (C) 1990-98 Stefan Becker
  7.  *
  8.  * This source code is for educational purposes only. You may study it
  9.  * and copy ideas or algorithms from it for your own projects. It is
  10.  * not allowed to use any of the source codes (in full or in parts)
  11.  * in other programs. Especially it is not allowed to create variants
  12.  * of ToolManager or ToolManager-like programs from this source code.
  13.  *
  14.  */
  15.  
  16. #include "toolmanager.h"
  17.  
  18. /* Local data */
  19. static struct Library *LocaleBase = NULL;
  20. static struct Catalog *Catalog    = NULL;
  21. static const struct TagItem CatalogParams[] = {
  22.  OC_BuiltInLanguage, (ULONG) "english",
  23.  OC_Version,         TMCATALOGVERSION,
  24.  TAG_DONE
  25. };
  26.  
  27. /* Initialize localization */
  28. #undef  DEBUGFUNCTION
  29. #define DEBUGFUNCTION InitLocale
  30. void StartLocale(void)
  31. {
  32.  LOCALE_LOG(LOG0(Entry))
  33.  
  34.  /* Open locale.library */
  35.  if (LocaleBase = OpenLibrary("locale.library", 38)) {
  36.  
  37.   LOCALE_LOG(LOG1(LocaleBase, "0x%08lx", LocaleBase))
  38.  
  39.   /* Open catalog */
  40.   Catalog = OpenCatalogA(NULL, TMCATALOGNAME, CatalogParams);
  41.  
  42.   LOCALE_LOG(LOG1(Catalog, "0x%08lx", Catalog))
  43.  }
  44. }
  45.  
  46. /* Free locale stuff */
  47. #undef  DEBUGFUNCTION
  48. #define DEBUGFUNCTION StopLocale
  49. void StopLocale(void)
  50. {
  51.  LOCALE_LOG(LOG0(Entry))
  52.  
  53.  /* Library opened? */
  54.  if (LocaleBase) {
  55.  
  56.   /* Catalog opened? */
  57.   if (Catalog) {
  58.  
  59.    /* Close catalog and clear pointer */
  60.    CloseCatalog(Catalog);
  61.    Catalog = NULL;
  62.   }
  63.  
  64.   /* Close library and clear pointer */
  65.   CloseLibrary(LocaleBase);
  66.   LocaleBase = NULL;
  67.  }
  68. }
  69.  
  70. /* Translate one string */
  71. #undef  DEBUGFUNCTION
  72. #define DEBUGFUNCTION TranslateString
  73. const char *TranslateString(const char *text, ULONG id)
  74. {
  75.  LOCALE_LOG(LOG3(Arguments, "Default '%s' (0x%08lx) ID %ld", text, text, id))
  76.  
  77.  /* Return string from catalog or default text */
  78.  return(LocaleBase ? GetCatalogStr(Catalog, id, text) : text);
  79. }
  80.